<?php
/**
 * Created by PhpStorm.
 * User: 1
 * Date: 2019/2/19
 * Time: 16:46
 */

namespace App\Http\Controllers;

use Dingo\Api\Routing\Helpers;
use Illuminate\Support\Facades\Validator;


//所有的验证权限 日志基类
class BaseApiController extends \Illuminate\Routing\Controller
{
    use Helpers;

    public function __construct()
    {

    }

    public function log()
    {
    }

    //验证器
    public function validate($rule,$request){
        //传入规则(数组形式),接收的数据
        //验证规则,返回错误信息
        $validate = Validator::make($request->all(),$rule);
        if ($validate->fails()) {
            $messages = [$validate->errors()->all(),'5001'];
            return json_encode($messages);
        }
    }

   //成功  返回数据
    public function success($data=[]){
        return  response()->json([
            'code'=>'200',
            'message'=>config('errorcode.code')[200],
            'data'=>$data,
        ]);
    }


    //失败   返回值、
    public function fail($code,$data=[]){
        return response()->json([
            'code'=>$code,
            'message'=>config('errorcode.code')[$code],
            'data'=>$data,
        ]);
    }
}